import request from "@/utils/request";

// 创建模板
export function addTemplate(data) {
  return request({
    url: "/support/template/addTemplate",
    method: "post",
    data: {
      centerCode: "work_order_center",
      ...data,
    },
  });
}
// 根据模板id查询模板详情
export function getTemplateById(id) {
  return request({
    url: "/support/template/getTemplateById",
    method: "get",
    params: {
      templateId: id,
    },
  });
}
// 创建模板并发布
export function addTemplatePublish(data) {
  return request({
    url: "/support/template/addTemplatePublish",
    method: "post",
    data: {
      centerCode: "work_order_center",
      ...data,
    },
  });
}

// 根据搜索条件查询工单模板
export function getTemplates(params) {
  return request({
    url: "/support/template/getTemplates",
    method: "get",
    params: {
      centerCode: "work_order_center",
      ...params,
    },
  });
}

// 发布模板
export function publishTemplate(id) {
  return request({
    url: "/support/template/publishTemplate",
    method: "get",
    params: {
      templateId: id,
    },
  });
}

// 删除模板
export function deleteTemplate(id) {
  return request({
    url: "/support/template/deleteTemplate",
    method: "get",
    params: {
      templateId: id,
    },
  });
}

// 获取模板名称列表
export function getTemplateNames(params) {
  return request({
    url: "/support/template/getTemplateNames",
    method: "get",
    params: {
      centerCode: "work_order_center",
      ...params,
    },
  });
}

// 获取流程节点
export function getActivitys(params) {
  return request({
    url: "/support/template/getActivitys",
    method: "get",
    params: {
      activityType: "work_order",
      ...params,
    },
  }).then((res) => {
    // console.log('res',res)
    res.data.forEach((t) => {
      t.id = "" + t.id;
    });
    return res;
  });
}

// 获取流程节点详情
export function getActivityByKey(modelKey) {
  return getActivitys({
    modelKey,
  }).then((res) => {
    return res.data[0];
  });
}

// 查询组织机构
export function getOrg(data) {
  return request({
    url: "/support/template/getOrg",
    method: "post",
    headers: {
      repeatSubmit: false,
      showErrorMsg: false,
    },
    data: {
      ...data,
      flag: 1,
    },
  });
  /*
  // 查询第一个组织机构
  let data = {
    treeType: "01",
    orgType: "1",
    innerOrgFlag: "1",
    orgCode: ""
  }
  return request({
    url: '/orgCenter/organiztionTree',
    method: 'post',
    data
  })
  */
}

// 修改图片
export function updateImg(params) {
  return request({
    url: "/support/template/updateImg",
    method: "get",
    params,
  });
}

// 逾期配置
export function overdueEdit(data) {
  return request({
    url: "/support/template/overdueEdit",
    method: "post",
    data,
  });
}
// 查询租户列表
export function lesseeList() {
  return request({
    url: "/support/lessee/list",
    method: "get",
  });
}
//配置优选
export function excellent(data) {
  console.log(data);
  return request({
    url: "/support/template/excellent",
    method: "post",
    data,
  });
}
//配置优选
export function getExcellent(id) {
  return request({
    url: "/support/template/getExcellent",
    method: "get",
    params: {
      templateId: id,
    },
  });
}
